<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="css/layout.css">

        <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<!--        <script src="js/main.js"></script>-->
        <title></title>
    </head>
    <body>

<?php

require_once 'readFolder.php';
require_once 'structure.php';

$data = array();
readFolder('folder', $data);
/*
$data = array(
    "ordner 1" => array(
        "type" => "folder",
        "items" => array(
            "ordner 2" => array(
                "type" => "folder",
                "items" => array(
                    "ordner 3" => array(
                        "type" => "folder",
                        "items" => null
                    ),
                    "ordner 4" => array(
                        "type" => "folder",
                        "items" => array(
                            "file 3" => array(
                                "type" => "file",
                                "items" => null
                            )
                        )
                    ),
                    "file 2" => array(
                        "type" => "file",
                        "items" => null
                    )
                )
            ),
            "file 1" => array(
                "type" => "file",
                "items" => null
            )
        )
    )
);
*/
/*$input = '{"d:ordner 1":{"d:ordner 2":{"0":"d:ordner 3","d:ordner 4":["f:file 3"],"1":"f:file 2"},"0":"f:file 1"}}';
$data = json_decode($input);*/

//echo '<pre>';

//$structure = new structure();

createBox($data);

function createBox($data, $margin = -64) {
    foreach ($data as $title => $info) {
        // create new box
            // create info box for each $element["items"]
                // create folder or file box (check $element["type"])
                // create title box

        // check if $element["items"] is null
            // if null - break
            // if not null (= array), begin from top

        $items = $info["items"];
        $type = $info["type"];

        if ($items != null) {
            // create a parent box if there are child items
            echo '<div class="box" style="margin-left:' . (int)($margin + 64) . 'px;">' . PHP_EOL;

                // create info box for each file or folder
                echo '<div class="info">' . PHP_EOL;
                    echo '<div class="' . $type . '"></div>' . PHP_EOL;
                    echo '<div class="title">' . $title . '</div>' . PHP_EOL;
                echo '</div>' . PHP_EOL;

            // do it for each childs
            createBox($items, count($items));

            echo '</div>' . PHP_EOL;
        } else {
            // create info box for each file or folder
            echo '<div class="info">' . PHP_EOL;
                echo '<div class="' . $type . '"></div>' . PHP_EOL;
                echo '<div class="title">' . $title . '</div>' . PHP_EOL;
            echo '</div>' . PHP_EOL;
        }
    }
}




function createDots($count) {
    for ($i = 0; $i < $count; $i++ ) {
        echo '<div class="dots">' . PHP_EOL;
            echo '<div class="dot-top corner"></div>' . PHP_EOL;
            echo '<div class="dot-bottom hide"></div>' . PHP_EOL;
        echo '</div>' . PHP_EOL;
    }
}


//echo $structure->save();


/*
array(
    "d:ordner 1" => array(
        "d:ordner 2" => array(
            "d:ordner 3",
            "d:ordner 4" => array(
                "f:file 3"
            ),
            "f:file 2"
        ),
        "f:file 1"
    )
)


*/
?>
</body>
</html>